﻿// This file is part of Code4Public (http://code4public.codeplex.com)
// Copyright 2011 Sina Iravanian - <sina@sinairv.com>
//
// This source file(s) may be redistributed, altered and customized
// by any means PROVIDING the authors name and all copyright
// notices remain intact.
// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED. USE IT AT YOUR OWN RISK. THE AUTHOR ACCEPTS NO
// LIABILITY FOR ANY DATA DAMAGE/LOSS THAT THIS PRODUCT MAY CAUSE.
// ------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Code4Public.Settings;

namespace Code4Public.ThemeDesigners
{
    [DefaultEvent("HeaderThemeChanged")]
    public partial class ThemeHeaderDesigner : UserControl
    {
        public ThemeHeaderDesigner()
        {
            InitializeComponent();
        }

        public BorderInfo HeaderBorder
        {
            get
            {
                return new BorderInfo()
                {
                    Bottom = this.headerBorderDesigner.BorderBottom,
                    Right = this.headerBorderDesigner.BorderRight,
                    Left = this.headerBorderDesigner.BorderLeft,
                    Top = this.headerBorderDesigner.BorderTop,
                    Color = this.headerBorderDesigner.BorderColor
                };
            }

            set
            {
                this.headerBorderDesigner.BorderBottom = value.Bottom;
                this.headerBorderDesigner.BorderLeft = value.Left;
                this.headerBorderDesigner.BorderRight = value.Right;
                this.headerBorderDesigner.BorderTop = value.Top;
                this.headerBorderDesigner.BorderColor = value.Color;
            }
        }
        
        public FontInfo HeaderFont
        {
            get
            {
                return new FontInfo(this.headerFontDesigner.FontColor,
                    this.headerFontDesigner.FontBold, this.headerFontDesigner.FontItalic);
            }

            set
            {
                this.headerFontDesigner.FontBold = value.Bold;
                this.headerFontDesigner.FontItalic = value.Italic;
                this.headerFontDesigner.FontColor = value.Color;
            }
        }

        public int HeaderFontSize
        {
            get
            {
                return this.headerFontDesigner.FontSize;
            }

            set
            {
                this.headerFontDesigner.FontSize = value;
            }
        }

        public Color HeaderBackColor
        {
            get
            {
                return this.colorPickerBackColor.Color;
            }

            set
            {
                this.colorPickerBackColor.Color = value;
            }
        }

        private bool eventSuspended = false;

        public void SuspendEventRaising()
        {
            eventSuspended = true;
            this.headerBorderDesigner.SuspendEventRaising();
            this.headerFontDesigner.SuspendEventRaising();
        }

        public void ResumeEventRaising()
        {
            eventSuspended = false;
            this.headerFontDesigner.ResumeEventRaising();
            this.headerBorderDesigner.ResumeEventRaising();
        }

        public event EventHandler HeaderThemeChanged;

        private void headerFontDesigner_FontPropertiesChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && HeaderThemeChanged != null)
            {
                HeaderThemeChanged(this, new EventArgs());
            }
        }

        private void headerBorderDesigner_BorderPropertiesChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && HeaderThemeChanged != null)
            {
                HeaderThemeChanged(this, new EventArgs());
            }
        }

        private void colorPickerBackColor_ColorChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && HeaderThemeChanged != null)
            {
                HeaderThemeChanged(this, new EventArgs());
            }
        }

    }
}
